package com.yanqu.road.server.logic.activity.condition.langyabang;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.LangYaBuildingCoinArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseUserYRankCondition;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.Objects;

public class LangYaUserScoreRankCondition  extends BaseUserYRankCondition {
    public LangYaUserScoreRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }
    @Override
    protected void player_BoardLevelHandle(Object object) {
        LangYaBuildingCoinArgs args = (LangYaBuildingCoinArgs) object;

        if(StringUtils.isNullOrEmpty(getParam())){
            setParam("0");
        }
        boolean needUpdate = false;
        if (args.getCoinValue() > getValue().longValue()){
            setValue(BigInteger.valueOf(args.getCoinValue()));
            needUpdate = true;
        }
        if (args.getBuildingValue() > Integer.valueOf(getParam())){
            setParam(String.valueOf(args.getBuildingValue()));
            needUpdate = true;
        }
        if (needUpdate){
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.LangYaUserBuildingCoinRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.LangYaUserBuildingCoinRank.getValue(), handle);
    }


}
